package org.geektimes.configuration.microprofile.config.source;

import org.eclipse.microprofile.config.spi.ConfigSource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @Author: menglinggang
 * @Date: 2021-03-15
 * @Time: 3:35 下午
 */
public class FileConfigSource implements ConfigSource {

    private Properties properties;

    public FileConfigSource(){
        InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("config.properties");
        properties = new Properties();
        try {
            properties.load(resourceAsStream);
            properties.setProperty(CONFIG_ORDINAL, "200");
        } catch (IOException e) {
           throw new RuntimeException(e);
        }
    }

    @Override
    public Set<String> getPropertyNames() {
        return properties.stringPropertyNames();
    }

    @Override
    public String getValue(String s) {
        return properties.getProperty(s);
    }

    @Override
    public String getName() {
        return "java file";
    }
}
